<?php

session_start();
if(!isset($_SESSION['userId']))
{
	header("location:index.php");
}
include("../class/config.php");
include("../class/cls_program.php");

if(isset($_POST['add']))
{
	$program_name=$_POST['program_name'];
	$date=date("Y-m-d H:i:s");
	$objProgram->addProgram($program_name,$date);
	$success="Program added successfully.";
}
if(isset($_GET['deleteId']))
{
	$ProgId=$_GET['deleteId'];
	$objProgram->deleteProgram($ProgId);
	}
if(isset($_GET['editId']))
{
	$progId=$_GET['editId'];
		if(isset($_POST['edit']))
			{
				$progName=$_POST['category_name'];
				$Date=date("Y-m-d h:i:s");
				$objProgram->editProgram($progId,$progName,$Date);
				
			}
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Program</title>
<script type="text/javascript" src="../lib/frmValidation.js">
</script>
<link rel="stylesheet" href="../css/layout.css" />
</head>
<body>

	<div class="mainWrapper">
     <?php include("../includes/adminHeader.php");?>
    
    
    <div class="bodyContent">
    <h1>Program</h1>
    <div class="innerBody">
    <?php if(!isset($_GET['action']))
	{?>
    <strong>Program Listing</strong>  | <a href="?action=add">Add Program</a>
     
	
      <table width="100%" border="0" cellpadding="1" cellspacing="1" class="table">
        <tr>
          <th>Sn</th>
          <th>Program Added Date</th>
          <th>Program Name</th>
          <th>Action</th>
        </tr>
		<?php $resProgram = $objProgram->selectProgram();
		$i=1;
		
		while($recProgram=mysqli_fetch_array($resProgram))
		{
		?>
        <tr>
          <td><?php echo $i++;?></td>
          <td><?php echo $recProgram['program_added_date'];?></td>
          <td><?php echo $recProgram['program_name'];?></td>
		  
          <td><a href="?action=edit&editId=<?php echo $recProgram['program_id'];?>">Edit</a> | <a href="?deleteId=<?php echo $recProgram['program_id'];?>" onclick="javascript:return confirm('Are You Sure You Want to Delete this Record?')">Delete</a></td>
        </tr>
        <?php } /// end of while($recCategory=mysqli_fetch_array($resCategory))
?>
       </table>
       
     <?php }
	 else if(isset($_GET['action']) && $_GET['action']=='edit')
	 {
		 $progId=$_GET['editId'];
		 $res=$objProgram->getProgramById($progId);
		 $rec=mysqli_fetch_array($res);
//	 echo "<pre>";
//                 print_r ($rec);
//         echo "<pre/>";
// exit;	 ?>
      <strong>Edit Category</strong>
      <form id="categoryEdit" name="categoryEdit" method="post" action="" onsubmit="return editCat()">
        <table width="100%" border="0" class="table" cellpadding="1" cellspacing="1">
          <tr>
            <td width="30%">Program Name *</td>
            <td><input type="text" name="category_name" id="category_name" class="textBox" value="<?php echo $rec['program_name'];?>" /></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><input type="submit" name="edit" id="edit" value="Edit" />
            	<input type="button" name="cancel" value="cancel" onclick="javascript:location.href='category.php'" /></td>
          </tr>
          <tr>
            <td>Note : * Fields are mandatory.</td>
            <td>&nbsp;</td>
          </tr>
        </table>
      </form>
 <?php }
	 else if(isset($_GET['action']) && $_GET['action']=='add')
	 {
	 
	 ?>
      <strong>Add Category</strong>
      <?php 
	  if(isset($success))
      {
      echo $success;
      } ?>
      <form id="addCategory" name="addCategory" method="post" action="" onsubmit="return addCat()">
        <table width="100%" border="0" class="table" cellpadding="1" cellspacing="1">
          <tr>
            <td width="30%">Program Name *</td>
            <td><input type="text" name="program_name" id="program_name" class="textBox" /></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><input type="submit" name="add" id="add" value="Add"  />
            	<input type="button" name="cancel" value="cancel" onclick="javascript:location.href='program.php'" /></td>
          </tr>
          <tr>
            <td>Note : * Fields are mandatory.</td>
            <td>&nbsp;</td>
          </tr>
        </table>
      </form>
<?php }?>
    </div>
    
    </div>
    
    
    <?php include("../includes/adminFooter.php");?>
     
       </div>

</body>
</html>